from torch.utils.tensorboard import SummaryWriter
import numpy
from PIL import Image

writer = SummaryWriter("logs")
for i in range(100):
    writer.add_scalar("x=y", i, i)
    writer.add_scalar("y=3x", 3 * i, i)
    writer.add_scalar("y=x*x", i * i, i)

img_path = "datas/train/ants/0013035.jpg"
image = Image.open(img_path)
img_array = numpy.array(image)

print(type(img_array))
print(img_array.shape)
# 从PIL到numpy , 需要在 add_image 中指定 shape 中每个数字、维的含义，
writer.add_image("test_add_image", img_array, 1, dataformats="HWC")

img_path = "datas/train/bees/16838648_415acd9e3f.jpg"
image = Image.open(img_path)
img_array = numpy.array(image)

print(type(img_array))
print(img_array.shape)
# 从PIL到numpy , 需要在 add_image 中指定 shape 中每个数字、维的含义，
writer.add_image("test_add_image", img_array, 2, dataformats="HWC")

writer.close()

# 终端运行：  tensorboard --logdir=logs --port=6777
